package com.sihai.ehr.web.action.contract;

import com.sihai.core.beans.BeanInject;
import com.sihai.ehr.model.biz.*;
import com.sihai.ehr.service.ContractService;
import com.sihai.ehr.web.action.EHRAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import java.util.List;


@Results({
        @Result(name = "detail",location = "audit_detail.jsp")
})
public class ContractVerAuditAction extends EHRAction{

    @BeanInject
    private ContractService contractService;

    private Long versionId;
    private List<List<ContractVersionAuditing>> audits;
    private ContractVersion contractVersion;
    //显示审核详细页面
    @Action("/contract/version_audit_detail")
    public String detail() throws Exception {
        contractVersion=contractService.getVersion(versionId);
        audits = contractService.findContractVersionAuditing(versionId);
        if(audits == null || audits.isEmpty()){
            contractService.saveContractVersioniAuditingProcess(versionId);
            audits = contractService.findContractVersionAuditing(versionId);
        }
        //检查当前登录用户是否可以审核当前结点
        if(audits != null && !audits.isEmpty()){
            checkCanAudit((Duty)null, audits.get(audits.size()-1));
        }
        currentAuditType = AuditType.audit_contract_version.toString();
        return "audit_detail";
    }

    public List<List<ContractVersionAuditing>> getAudits() {
        return audits;
    }

    public void setAudits(List<List<ContractVersionAuditing>> audits) {
        this.audits = audits;
    }

    public Long getVersionId() {
        return versionId;
    }

    public void setVersionId(Long versionId) {
        this.versionId = versionId;
    }

    public ContractVersion getContractVersion() {
        return contractVersion;
    }

    public void setContractVersion(ContractVersion contractVersion) {
        this.contractVersion = contractVersion;
    }
}
